package com.bless.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bless.common.core.controller.BaseController;
import com.bless.common.core.domain.AjaxResult;
import com.bless.system.domain.SysBless;
import com.bless.system.service.ISysBlessService;
import com.bless.common.utils.poi.ExcelUtil;
import com.bless.common.core.page.TableDataInfo;

/**
 * 祝福语Controller
 *
 * @author bless
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/system/bless")
public class SysBlessController extends BaseController {
    @Autowired
    private ISysBlessService sysBlessService;

    /**
     * 查询祝福语列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysBless sysBless) {
        startPage();
        List<SysBless> list = sysBlessService.selectSysBlessList(sysBless);
        return getDataTable(list);
    }

    /**
     * 导出祝福语列表
     */
    @PreAuthorize("@ss.hasPermi('system:bless:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBless sysBless) {
        List<SysBless> list = sysBlessService.selectSysBlessList(sysBless);
        ExcelUtil<SysBless> util = new ExcelUtil<SysBless>(SysBless.class);
        util.exportExcel(response, list, "祝福语数据");
    }

    /**
     * 获取祝福语详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysBlessService.selectSysBlessById(id));
    }

    /**
     * 新增祝福语
     */
    @PreAuthorize("@ss.hasPermi('system:bless:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SysBless sysBless) {
        sysBless.setAddTime(new Date());
        return toAjax(sysBlessService.insertSysBless(sysBless));
    }

    /**
     * 修改祝福语
     */
    @PreAuthorize("@ss.hasPermi('system:bless:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SysBless sysBless) {
        return toAjax(sysBlessService.updateSysBless(sysBless));
    }

    /**
     * 删除祝福语
     */
    @PreAuthorize("@ss.hasPermi('system:bless:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBlessService.deleteSysBlessByIds(ids));
    }
}
